package com.james.customcamera.presenter;

import com.james.customcamera.base.BasePresenter;
import com.james.customcamera.bean.HomeBean;
import com.james.customcamera.contract.HomeContract;
import com.james.customcamera.model.HomeModel;
import com.james.customcamera.mvp.IModel;
import com.james.customcamera.ui.fragment.HomeFragment;

import java.util.HashMap;

/**
 * Created by James on 2018/2/9 0009.
 */

public class HomePresenter extends BasePresenter<HomeFragment> implements HomeContract.HomePresenter {

    @Override
    public HashMap<String, IModel> getiModelMap() {
        return loadModelMap(new HomeModel());
    }

    @Override
    public HashMap<String, IModel> loadModelMap(IModel... models) {
        HashMap<String, IModel> map = new HashMap<>();
        map.put("getHomePhotos", models[0]);
        return map;
    }

    @Override
    public void getPhotos(int page) {
        ((HomeModel) getiModelMap().get("getHomePhotos")).getHomePhotos(page, new HomeModel.DataListener<HomeBean>() {
            @Override
            public void successInfo(HomeBean result) {
                getIView().loadPhotos(result);
            }

            @Override
            public void failInfo(String result) {

            }
        });
    }

    @Override
    public void refreshPhotos(int page) {

    }

    @Override
    public void loadMorePhotos(int page) {
        ((HomeModel) getiModelMap().get("getHomePhotos")).getHomePhotos(page, new HomeModel.DataListener<HomeBean>() {
            @Override
            public void successInfo(HomeBean result) {
                getIView().loadMorePhotos(result);
            }

            @Override
            public void failInfo(String result) {

            }
        });
    }


}
